﻿using MediatR;
using T.Settlement.API.Application.Command.PaymentCommand;
using T.Settlement.Repository.SettlementImpl;
using T.Settlement.Repository.SettlementInterface;

namespace T.Settlement.API.Application.CommandHandlers.PaymentHandler
{
    public class PaymentBatchDelCommandHandler : IRequestHandler<PaymentBatchDelCommand, int>
    {
        private readonly IPaymentSRepository _paymentSRepository;
        public PaymentBatchDelCommandHandler(IPaymentSRepository paymentSRepository)
        {
            _paymentSRepository = paymentSRepository;
        }

        public async Task<int> Handle(PaymentBatchDelCommand request, CancellationToken cancellationToken)
        {
            var list = await _paymentSRepository.GetAllAsync();
            var ilist = list.Where(x => request.PaymentId.Contains(x.PaymentId.ToString())).ToList();
            foreach (var x in ilist)
            {
                x.IsDeleted = true;
            }
            return await _paymentSRepository.UpdateRange(ilist);
        }
    }
}
